package lib.bone.flow.dao;

import lib.bone.flow.domain.entity.FlowWork;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Optional;

public interface FlowWorkDAO extends JpaRepository<FlowWork,String> {
    /**
     * 删除流程实例信息
     * @param id
     */
    void deleteById(String id);

    Optional<FlowWork> findByServiceId(String id);


    /**
     * ID in 查询
     * @param ids
     * @return
     */
    List<FlowWork> findByIdIn(List<String> ids);


    List<FlowWork> findByInitiator(String userId);

    List<FlowWork> findAllByCurrentNodeId(String currentNodeId);

    @Query(value = "select * from flow_work where flow_name = ?1 and flow_work_status = ?2 and Date(created_time) < '2023-01-01'", nativeQuery = true)
    List<FlowWork> findKycCheck(String flowName,String flowWorkStatus);


    List<FlowWork> findByFlowDefineCodeAndInitiator(String flowDefineCode,String initiator);

    List<FlowWork> findByFlowDefineCodeAndCurrentNodeIdAndFlowWorkStatus(String flowDefineCode, String currentNodeId,String flowWorkStatus);

    @Query(value = "select * from flow_work where flow_name = ?1 and (flow_work_status = ?2 or flow_work_status = ?3) and Date(created_time) > '2023-01-01' and initiator = ?4", nativeQuery = true)
    List<FlowWork> getOverNumber(String flowName,String flowWorkStatus1,String flowWorkStatus2,Long initiator);

    @Query(value = "select * from flow_work where flow_name = ?1 and flow_work_status = ?2 and Date(created_time) > '2023-01-01'", nativeQuery = true)
    List<FlowWork> findJwcCheck(String flowName,String flowWorkStatus);

}
